home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Applications / ARTAbrot 1.0 / MBROT.S < prev    next >
Text File  |  1993-08-24  |  6KB  |  195 lines

  1. /************************************************************************/
  2. /*                                                                        */
  3. /*    FILE:    MBROT.S -- MANDELBROT DSP3210 PROGRAM                        */
  4. /*                                                                        */
  5. /*    PURPOSE:    DSP3210 routines to generate Mandelbrot image data.        */
  6. /*                                                                        */
  7. /*    AUTHOR:    George T. Warner                                            */
  8. /*                                                                        */
  9. /*    NOTES:    Variables at param block must be initialized                */
  10. /*            before setting Startflag to allow the program to run.  The    */
  11. /*            results are stored in RAM starting at address OutputData.    */
  12. /*            Program completes by writing a nonzero value to Doneflag.    */
  13. /*                                                                        */
  14. /*    REVISIONS:                                                            */
  15. /*    08/22/93    GTW    Converted from VCOS to ARTA code.                    */
  16. /*    02/14/92    GTW    Cleaned up.                                            */
  17. /*    12/23/91    GTW    First working DSP3210 version.                        */
  18. /*                                                                        */
  19. /************************************************************************/
  20.  
  21. #include "DSP3210.h"
  22.  
  23. /* Macro for PC relative addressing. */
  24. #define AddressPR(LAB) pc + LAB - (.+8)
  25.  
  26. NewModule(MBrot, kdspSmoothModule, kdspAutoCache, cmain)
  27.     long    100, 4, 655        /* I don't know about this. */
  28.  
  29. NewCachedProgramSection(cmain, MBrot)
  30. NewParameterSection(brobuf, kdspAppSpecificData, MBrot)
  31.  
  32. AppendSection(cmain)
  33.     *sp++ = r5
  34.     *sp++ = r6
  35.     *sp++ = r8
  36.     *sp++ = r10
  37.     *sp++ = r11
  38.     *sp++ = r13
  39.     *sp++ = r14
  40.     *sp++ = r18                    /* Push r18 onto stack. */
  41.  
  42.     GetSectionAddress(r5, brobuf)    /* Get address for brobuf and put in r5.    */
  43.     /* Once I get the section base address in a register (r5), I can make all    */
  44.     /* future accesses by register relative addressing.                            */
  45.  
  46.     r2 = r5 + (Inited - Startflag)        // r2 = Inited
  47.  
  48.     r1 = *r2
  49.     nop
  50.     if(ne) pcgoto Wait_for_go    /* Go ahead if initialized. */
  51.     r1 = (short) 1
  52.  
  53.     r3 = r5 + (Startflag - Startflag)        // r3 = Startflag
  54.     *r3 = r0                    /* Clear startflag. */
  55.     r4 = r5 + (Doneflag - Startflag)        // r4 = Doneflag
  56.     *r4 = r0                    /* Clear doneflag. */
  57.     *r2 = r1                    /* Set inited flag. */
  58.  
  59. Wait_for_go:
  60.     r4 = r5 + (Startflag - Startflag)        // r4 = Startflag
  61.     r3 = *r4
  62.     nop
  63.     if(eq) pcgoto exit            /* Be a "good citizen" and return. */
  64.     nop
  65.  
  66.     *r4 = r0                    /* Clear Startflag. */
  67.  
  68.     r13 = r0                    /* Zero point counter. */
  69.     r10 = r5 + (OutputData - Startflag)        // r10 = OutputData            /* Set pointer to output data. */
  70.     r14 = r5 + (Maxiter - Startflag)        // r14 = Maxiter
  71.     r14 = *r14                    /* Get the maximum number of iterations. */
  72.     r8 = AddressPR(Scrfl)                    /* Set pointer to temp storage. */
  73.     
  74.     r2 = r5 + (Xstart - Startflag)        // r2 = Xstart                    /* Convert IEEE format. */
  75.     r3 = AddressPR(myXstart)
  76.     /* Use these to convert from IEEE to DSP3210 format. */
  77.     *r3++ = a0 = dsp(*r2++)
  78.     *r3++ = a0 = dsp(*r2++)
  79.     *r3 = a0 = dsp(*r2)
  80.                                 /* Compute y coordinate. */
  81.     /* r11 - iteration count. */
  82.     /* r13 - point counter. */
  83.     /* r14 - max iterations. */
  84.     /* r8  - pointer to temp storage. */
  85. Mloop:
  86.     r2 = AddressPR(Scrlong)        /* Set pointer to temp storage. */
  87.     *r2 = r13                    /* Store in memory. */
  88.     r3 = AddressPR(myDelta)        /* Set pointer to delta x. */
  89.     a0 = float32(*r2)            /* Convert count to floating point. */
  90.     r6 = AddressPR(myXstart)    /* Set pointer to base x. */
  91.     r11 = AddressPR(Zero)
  92.     a2 = *r6 + a0 * *r3            /* Coordinate=base+(pointnum * deltaX) */
  93.     r3 = AddressPR(myYstart)
  94.     a3 = *r3                    /* Get imaginary cooridinate (y). */
  95.     a0 = *r11                    /* Zero the accumulator. */
  96.     a1 = *r11                    /* Zero the accumulator. */
  97.     *r8++ = a2 = a2                /* Save real c. */
  98.     *r8-- = a3 = a3                /* Save imaginary c. */
  99.     r11 = r0                    /* Zero iteration count. */
  100.  
  101. Mandel: 
  102.     pccall TestMag(r18)
  103.     r11 = r11 + 1                /* Increment iteration count. */
  104.  
  105.     if(ne) pcgoto Pointdone        /* This point diverged; it's done. */
  106.     nop
  107.  
  108.     r11 - r14                    /* Compare to max. num. of iterations. */
  109.     if(ge) pcgoto Pointdone        /* Return if greater than or equal to. */
  110.     nop
  111.  
  112.  
  113.     /* Now the famous z = z^2 + C function */
  114. DoTheBrot:
  115.     a2 = a0 * a1
  116.     a3 = a0 * a0
  117.     a0 = a3 - a1 * a1            /* This gives the real part of z squared. */
  118.     a1 = a2 + a2                /* This gives the imaginary part of z squared. */
  119.     a0 = a0 + *r8++                /* This is the +C (real) part of the equation. */
  120.     pcgoto Mandel
  121.     a1 = a1 + *r8--                /* This is the +C (img.) part of the equation. */
  122.  
  123. Pointdone:
  124.     *r10++ = (short)r11            /* Save result. */
  125.     r2 = r5 + (Points - Startflag)        // r2 = Points
  126.     r2 = *r2                    /* Get the number of points to do. */
  127.     r13 = r13 + 1
  128.     r2 - r13                    /* Are there more points to do? */
  129.     if(gt) pcgoto Mloop            /* If so, go do next point. */
  130.     nop 
  131.  
  132. Linedone:
  133.     r14 = (short)0x69            /* Just an arbitrary non-zero number. */
  134.     r4 = r5 + (Doneflag - Startflag)    // r4 = Doneflag
  135.     *r4 = r14                    /* Indicate that DSP is done. */
  136.  
  137. exit:
  138.     r4 = sp - 4
  139.     r18 = *r4--                    /* Pull r18 off stack. */
  140.     r14 = *r4--                    /* Pull r14 off stack. */
  141.     r13 = *r4--                    /* Pull r13 off stack. */
  142.     r11 = *r4--                    /* Pull r11 off stack. */
  143.     r10 = *r4--                    /* Pull r10 off stack. */
  144.     r8 = *r4--                    /* Pull r8 off stack. */
  145.     r6 = *r4--                    /* Pull r6 off stack. */
  146.     r5 = *r4--                    /* Pull r5 off stack. */
  147.     sp = sp - 32                /* Restore stack pointer. */
  148.     return(r18)
  149.     nop
  150.  
  151. /************************************************************************/
  152. /* TestMag -- subroutine to compare magnitude of complex number in a0    */
  153. /*        and a1 to 2.0.  If greater, r1 = 1 upon exiting; if                */
  154. /*        less, r1 = 0.                                                    */
  155. /************************************************************************/
  156. TestMag:
  157.     a3 = a0 * a0                /* Square real part. */
  158.     a3 = a3 + a1 * a1            /* Add to img. part squared. */
  159.     r2 = AddressPR(Four)
  160.     a3 = a3 - *r2                /* Compare to 4.0. */
  161.     nop
  162.     nop
  163.     nop
  164.     if(alt) pcgoto Donef        /* If negative result, goto Done. */
  165.     r1 = r0
  166.     r1 = (short)1                /* Result did not diverge. */
  167. Donef:
  168.     return(r18)
  169.     r1 - 0                        /* Set flags based on result. */
  170.  
  171. Four:        float 4.0            /* Number for magnitude comparisons. */
  172. Zero:        float 0.0
  173. Scrfl:        2 * float            /* Scratch pad. */
  174. Scrlong:    long                /* Scratch pad. */
  175. myXstart:    float    0.0
  176. myDelta:    float    0.0
  177. myYstart:    float    0.0
  178.  
  179.  
  180. AppendSection(brobuf)
  181. /* Note: Xstart, Delta, and Ystart all hold IEEE representations of    */
  182. /* floating point values.  Hence, they have been declared as longs    */
  183. /* in order that they not be confused with DSP floats.                */
  184.  
  185. Startflag:    int        0
  186. Doneflag:    int        0
  187. Points:        long    640        /* Number of points. */
  188. Maxiter:    long    63        /* Maximum number of iterations. */
  189. Xstart:        long    80        /* Starting real (x) coordinate. */
  190. Delta:        long    80        /* Delta x. */
  191. Ystart:        long    80        /* y coordinate. */
  192. Inited:        long    0        /* Initialization flag. */
  193. OutputData:
  194.             640 * short
  195.